<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui" xmlns:t="http://myfaces.apache.org/tomahawk"
	template="/pages/template/main-layout.xhtml">

	<ui:define name="content">
		<t:saveState value="#{evokServiceBean.serviceList}" />
		<t:saveState value="#{evokServiceBean.service}" />

		<p:selectOneMenu value="#{evokServiceBean.qyDomainId}" converter="longConverter"
			rendered="#{sessionUserBean.domain == null}">
			<f:selectItem itemLabel="" itemValue="" />
			<f:selectItems value="#{enumBean.domainList}" var="dp" itemLabel="#{dp.name}"
				itemValue="#{dp.id}" />
			<p:ajax listener="#{evokServiceBean.domainChange}" update="serviceList"/>
		</p:selectOneMenu>
		
		<p:panel header="#{msgs.therapy_service}" id="serviceInfo">
			<h:inputHidden value="#{evokServiceBean.service.id}" />
			<p:panelGrid style="width:100%;" columns="4" columnClasses="width10,width40,width10,width40">
				<h:outputLabel value="#{msgs.default_code}" />
				<p:inputText value="#{evokServiceBean.service.code}" type="text"
					widgetVar="txtCode"
					style="width:95%;" maxlength="40" />

				<h:outputLabel value="#{msgs.default_name} *" />
				<p:inputTextarea value="#{evokServiceBean.service.name}" id="txtName"
					style="width:95%" maxlength="150" required="true" label="#{msgs.default_name}"/>
				
				<h:outputLabel value="#{msgs.therapy_service_price}" />
				<p:inputText value="#{evokServiceBean.service.price}" style="width:95%;">
					<f:convertNumber maxFractionDigits="2" maxIntegerDigits="6" />
				</p:inputText>

				<h:outputLabel value="#{msgs.therapy_service_currency}" />
				<h:selectOneMenu value="#{evokServiceBean.service.currency}">
					<f:selectItem itemLabel="" itemValue="" />
					<f:selectItems value="#{sessionEnum['TherapyServiceCurrency']}" var="en" itemLabel="#{en.name}"
						itemValue="#{en.value}" />
				</h:selectOneMenu>

				<h:outputLabel value="#{msgs.therapy_service_unit}" />
				<h:selectOneMenu value="#{evokServiceBean.service.unit}">
					<f:selectItem itemLabel="" itemValue="" />
					<f:selectItems value="#{sessionEnum['TherapyUnit']}" var="en" itemLabel="#{en.name}"
						itemValue="#{en.value}" />
				</h:selectOneMenu>

				<h:outputLabel value="#{msgs.domain_remark}" />
				<p:inputTextarea value="#{evokServiceBean.service.remark}" style="width:95%" rows="5"
					maxlength="200" autoResize="false"/>
			</p:panelGrid>

			<f:facet name="footer">
				<h:panelGrid width="100%" columnClasses="left,right" columns="2">
					<p:commandButton value="#{msgs.button_delete}" icon="ui-icon-trash"
						oncomplete="confirmDeleteService.show()" />

					<h:panelGroup >
						<p:commandButton value="#{msgs.button_submit}"
							icon="ui-icon-disk" update="serviceInfo,serviceList,:messages"
							actionListener="#{evokServiceBean.submit}" />
						<h:outputText value="&#160;" />	
						<p:commandButton value="#{msgs.button_reset}" icon="ui-icon-arrowrefresh-1-n" update="serviceInfo, serviceList"
							process="@this" 
							actionListener="#{evokServiceBean.add}" />
					</h:panelGroup>
				</h:panelGrid>
			</f:facet>
		</p:panel>


		<p:dataTable id="serviceList" var="nd" value="#{evokServiceBean.serviceModel}" rowIndexVar="ri"
			selectionMode="single" widgetVar="wdgServiceList">

			<p:ajax event="rowSelect" listener="#{evokServiceBean.selectService}" 
				update=":mainform:serviceInfo" />

			<p:column style="width:20px;" headerText="#{msgs.table_index}">
				<h:outputText value="#{ri+1}" />
			</p:column>

			<p:column headerText="#{msgs.default_code}">
				<h:outputText value="#{nd.code}" />
			</p:column>

			<p:column headerText="#{msgs.therapy_service_name}" sortBy="#{nd.name}">
				<h:outputText value="#{nd.name}" />
			</p:column>

			<p:column headerText="#{msgs.therapy_service_unit}">
				<h:outputText value="#{nd.unit}" converter="enumConverter" enumName="TherapyUnit" />
			</p:column>

			<p:column headerText="#{msgs.therapy_service_price}">
				<h:outputText value="#{nd.price}" />
			</p:column>

			<p:column headerText="#{msgs.therapy_service_currency}">
				<h:outputText value="#{nd.currency}" converter="enumConverter" enumName="TherapyServiceCurrency" />
			</p:column>
		</p:dataTable>
	</ui:define>

	<ui:define name="dialog">
		<h:panelGrid>
			<p:confirmDialog message="#{msgs.info_sure_delete}" width="200" showEffect="explode"
				hideEffect="explode" header="POZOR" severity="alert" widgetVar="confirmDeleteService"
				modal="true">

				<p:commandButton value="DA" update=":mainform:serviceInfo,:mainform:serviceList,:messages"
					actionListener="#{evokServiceBean.delete}" oncomplete="confirmDeleteService.hide()" />

				<p:commandButton value="NE" onclick="confirmDeleteService.hide()" type="button" />
			</p:confirmDialog>
		</h:panelGrid>
	</ui:define>
</ui:composition>
